//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
//#pragma comment(linker,"/STACK:33554432") /*32Mb*/
#define _CRT_SECURE_NO_DEPRECATE
#include<sstream>
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<memory>
#include<string>
#include<vector>
#include<cctype>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;

typedef unsigned long long      ui64;
typedef long long               i64;
typedef	vector<int>             VI;
typedef	vector<bool>            VB;
typedef	vector<VI>              VVI;
typedef	vector<string>          VS;
typedef	pair<int,int>           PII;
typedef map<string,int>         MSI;
typedef set<int>                SI;
typedef set<string>             SS;
typedef map<int,int>            MII;
typedef	pair<double,double>     PDD;

#define PB                      push_back
#define MP                      make_pair
#define X                       first
#define Y                       second
#define FOR(i, a, b)            for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)           for(int i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b)             memset(a, b, sizeof(a))
#define SZ(a)                   int((a).size())
#define ALL(a)                  (a).begin(), (a).end()
#define RALL(a)                 (a).rbegin(), (a).rend()
#define INF                     (2000000000)

#ifdef _DEBUG
#define eprintf(...) fprintf (stderr, __VA_ARGS__)
#else
#define eprintf(...) assert (true)
#endif


VVI g;
VI used;

int main()
{
	int n;
	cin >> n;
	g.resize(n);
	used.resize(n);
	map<string,int> M;
	VI L(n);
	VS names;
	FOR(i,0,n) {
		string s1,s2;
		cin >> s1;
		int t;
		cin >> t;
		if( M.find(s1)==M.end() ) {
			M[s1] = SZ(M);
			L[M[s1]] = SZ(s1);
			names.PB(s1);
		}
		int a = M[s1];
		FOR(j,0,t) {
			cin >> s2;
			int b;
			if( M.find(s2)==M.end() ) {
				M[s2] = SZ(M);
				L[M[s2]] = SZ(s2);
				names.PB(s2);
			}
			b = M[s2];
			g[a].PB(b);
		}
	}
	string alert;
	getline(cin,alert);
	getline(cin,alert);
	VI D(n,INF);
	D[0] = SZ(alert);
	queue<int> q;
	q.push(0);
	set<int> who;
	
	while(!q.empty()) {
		int v = q.front();
		q.pop();
		if( D[v] > 140 )
			continue;
		who.insert(v);
		FOR(i,0,SZ(g[v])) {
			who.insert(g[v][i]);
			if( D[v] + 6 + L[v] < D[ g[v][i] ] ) {
				D[ g[v][i] ] = D[v] + 6 + L[v];
				q.push( g[v][i] );
			}
		}
	}
	
	VI res(ALL(who));
	cout << SZ(res) << endl;
	FOR(i,0,SZ(res))
		cout << names[res[i]] << endl;
	//"RT @: "
    return 0;
}